package com.flute.icrawler.app.listener;

import com.flute.icrawler.app.entity.CrawlResult;
import com.flute.icrawler.app.util.ParameterKey;
import com.flute.icrawler.framework.autoadjust.IntervalCrawlUrlPool;
import com.flute.icrawler.framework.autoadjust.FetchAdjuster.FetchStatus;
import com.flute.icrawler.framework.framework.CrawlUrl;
import com.flute.icrawler.framework.framework.listener.ICrawlTaskListener;
import com.flute.icrawler.policy.updatepolicy.framework.UpdatePolicyController;

public class UpdateModuleListenser implements ICrawlTaskListener {

	private UpdatePolicyController updatecontroller = UpdatePolicyController
			.getInstance();

	public UpdateModuleListenser(IntervalCrawlUrlPool crawlpool) {
		updatecontroller.start(crawlpool);
	}

	@Override
	public void update(CrawlUrl url) {
		CrawlResult result = (CrawlResult) url.getResultParameter(
				ParameterKey.RESULT_CRAWL).getValue();
		if (result.getFetchStatus() != null
				&& result.getFetchStatus() == FetchStatus.Success) {
			updatecontroller.submitUrl(url);
		}

	}

}
